//
// Maths.cpp for  in /home/goldbe_y//cpp/Maths/209ajust
//
// Made by yoni goldberg
// Login   <goldbe_y@epitech.net>
//
// Started on  Sat Jun 11 17:14:06 2011 yoni goldberg
// Last update Sat Jun 11 23:52:27 2011 leo faucon
//

#include "Maths.hpp"

Maths::Maths(std::vector<float> tab, std::vector<float> b) :
  x(tab),
  Ox(b),
  Tx(),
  total(),
  moy(),
  prob()
{
  Moyenne();
  Probabilite();
  Calc();
}


double             Maths::cnn(int nb1, int nb2)
{
  double   res = 1, div = 1;
  double	ret;
  for (int i = (nb1 <= (nb2 - nb1)) ? nb1 : (nb2 - nb1); i > 0; i--)
    {
      res *= (nb2--);
      div *= (i);
    }
  ret = (res/div);
  return (ret);
}

void		Maths::Calc()
{
  for (size_t i = 0; i < x.size(); i++)
    {
      float temp = total;
      std::cout << total << " * ";
      temp *= cnn(i, total);
      std::cout << cnn(i, total) << " * ";
      temp *= pow(prob, i);
      std::cout << pow(prob, i) << " * ";
      temp *= pow((1 - prob), (total - i));
      std::cout << pow((1 - prob), (total - i)) << std::endl;
      Tx.push_back(temp);
    }
  affTab(Tx);
}

void		Maths::Probabilite()
{
  prob = moy/total;
}

void		Maths::Moyenne()
{
  total = 0;
  moy = 0;
  for (size_t i = 0; i < Ox.size(); i++)
    {
      moy += (x[i] * Ox[i]);
      total += Ox[i];
    }
  moy /= total;
}

void		Maths::affTab(std::vector<float> & tab)
{
  std::cout << "-----------------" << std::endl;
  for (size_t i = 0; i < tab.size(); i++)
    std::cout << tab[i] << std::endl;
}
